using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using MemberMgr.Data.ManagerObjects;
using MemberMgr.Data.BusinessObjects;
using MemberMgr.Data.Base;

namespace MemberMgr.Data.UnitTests
{
	[TestFixture]
    public partial class tConsumptionMasterTests : UNuitTestBase
    {
        protected ItConsumptionMasterManager manager;
		
		public tConsumptionMasterTests()
        {
            manager = managerFactory.GettConsumptionMasterManager();
        }
		
		protected tConsumptionMaster CreateNewtConsumptionMaster()
		{
			tConsumptionMaster entity = new tConsumptionMaster();
			
			
			entity.Sum = 66;
			entity.Costtime = DateTime.Now;
			entity.Costaddress = "Test Test ";
			entity.Costcut = "Test Test Test Test";
			entity.Costpoint = 46;
			
			ItMemberManager tMemberManager = managerFactory.GettMemberManager();
			entity.TMember = tMemberManager.GetAll(1)[0];
			
			ItShopManager tShopManager = managerFactory.GettShopManager();
			entity.TShop = tShopManager.GetAll(1)[0];
			
			return entity;
		}
		protected tConsumptionMaster GetFirsttConsumptionMaster()
        {
            IList<tConsumptionMaster> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				tConsumptionMaster entity = CreateNewtConsumptionMaster();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                tConsumptionMaster entityA = CreateNewtConsumptionMaster();
				manager.Save(entityA);

                tConsumptionMaster entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                tConsumptionMaster entityA = GetFirsttConsumptionMaster();
				
				entityA.Sum = 24;
				
				manager.Update(entityA);

                tConsumptionMaster entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Sum, entityB.Sum);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                tConsumptionMaster entity = GetFirsttConsumptionMaster();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

